package com.mashibing.class06;

import java.util.*;

public class ShowComparator2 {

    public static class MyComparator implements Comparator<Integer>{

        // 负数 : 第一个数放在前
        // 正数 : 第二个数放在前
        // 0   : 谁放在前都行
        @Override
        public int compare(Integer o1, Integer o2) {
            if (o1 < o2) return 1;
            else if (o1 > o2) return -1;
            return 0;
        }
    }

    public static class Student{
        public String name;
        public int id;
        public int age;

        public Student(String name, int id, int age) {
            this.name = name;
            this.id = id;
            this.age = age;
        }
    }
    // 水Id小 水放在前面
    public static class IdComparator implements Comparator<ShowComparator2.Student>{
        // 如果返回负数,认为第一个参数应该排在前面,
        // 如果返回正数,认为第二个参数应该排在前面。
        // 如果返回0, 认为水放在前面无所谓.
        @Override
        public int compare(ShowComparator2.Student o1, ShowComparator2.Student o2) {
            if (o1.id < o2.id){
                return -1;
            } else if (o2.id < o1.id) {
                return 1;
            }
            return 0;
        }
    }

    public static void main(String[] args) {
        String str1 = "abf";
        String str2 = "abd";
        System.out.println(str1.compareTo(str2));

        PriorityQueue<ShowComparator2.Student> heap = new PriorityQueue<ShowComparator2.Student>(new ShowComparator2.IdComparator());
        ShowComparator2.Student s1 = new ShowComparator2.Student("张三",5,27);
        ShowComparator2.Student s2 = new ShowComparator2.Student("李四",1,17);
        ShowComparator2.Student s3 = new ShowComparator2.Student("王五",4,29);
        ShowComparator2.Student s4 = new ShowComparator2.Student("赵六",3,9);
        ShowComparator2.Student s5 = new ShowComparator2.Student("左七",2,34);
        heap.add(s1);
        heap.add(s2);
        heap.add(s3);
        heap.add(s4);
        heap.add(s5);
        System.out.println("============================");
        while (!heap.isEmpty()){
            ShowComparator2.Student student = heap.poll();
            System.out.println(student.id + "," + student.name + ", " +  student.age);
        }
    }
}
